﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Newtonsoft.Json;
using System.IO;

namespace Kevin.Framework.Data.OrmMapping
{
    public static class EntityBaseExtension
    {
        /// <summary>
        /// 批量插入 暂未开放
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        private static int Insert(this List<EntityBase> list)
        {
            int result = 0;
            List<IDbDataParameter> paras = new List<IDbDataParameter>();
            foreach (EntityBase item in list)
            {
                EntityBase obj = (EntityBase)item.Clone();
                obj.GetModifiedProperties();
                //obj.GetInsertSql(out paras);
                //
            }

            return result;
        }
        /// <summary>
        /// 将实体转换为JSON格式的对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>JSON</returns>
        public static string ToJSON(this EntityBase entity)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);

            JsonSerializer json = new JsonSerializer();
            json.Serialize(new JsonTextWriter(sw), entity);

            return sb.ToString();
        }
    }
}
